home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4875 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  47 lines

  1. Path: news.uni-jena.de!news
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Possible VC 4.0 bug?
  5. Date: 1 Feb 1996 13:17:20 GMT
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Message-ID: <4eqeh0$na8@fsuj01.rz.uni-jena.de>
  8. References: <4eor3o$d06@enterprise.turningpoint.com>
  9. Reply-To: mkt@isun04.inf.uni-jena.de
  10. NNTP-Posting-Host: isun07.inf.uni-jena.de
  11.  
  12. In article d06@enterprise.turningpoint.com, sathan@cybercom.net (Stephen Athanas) writes:
  13. > When I compile and run the following code under MSVC 4.0, I get an access 
  14. > violation on the delete:
  15. > class foo {
  16. > public :
  17. >     virtual ~foo( ) { printf( "In foo::~foo.\n" ) }
  18. > };
  19. > main() {
  20. >     foo* p = new foo[ 0 ];
  21. >     delete [] p;
  22. > }
  23. > Everything works fine, and the destructor is never called, if the destructor 
  24. > is not virtual.  <----------- DOES THIS MEAN: A VIRTUAL DESTRUCTOR IS CALLED?
  25. > Is this a problem with VC, or with my understanding of how a new of size zero 
  26. > should work? Thanks.
  27.  
  28. Of course, it is allowed to call new for an array of size zero.
  29. And the compiler should return a pointer to a unique memory location.
  30. (A second call to new for an array of zero size should give a pointer
  31.  different from the other.)
  32. Deleting such a pointer using delete[] is exacty the right thing to do!
  33. And regardless of a virtual or nonvirtual destructor: Since with the new [0]
  34. is NO object created, delete cannot call a destructor! (for which object
  35. should the destructor be invoked??? There is no object!)
  36.  
  37. Thats what the C++ standard says.
  38.  
  39. The only problem I see is: you should test if new returns 0.
  40.  
  41. Bye.
  42.  
  43.  
  44.